/*
 * Sym2x2XMLConfigFileParameters.java
 *
 * Created on 29 de Março de 2010, 18:26
 *
 */

package intopo.game.impl.sym2x2;

import intopo.evogame.partnerselection.config.ParsingException;
import intopo.game.AbstractDescriptionText;
import intopo.game.DescriptionGUI;

import intopo.game.gui.AbstractGameEditorComponent;
import intopo.game.gui.AbstractStrategyEditorComponent;
import intopo.game.gui.AbstractGlobalParametersComponent;
import java.io.PrintStream;
import java.lang.reflect.Constructor;
import java.util.Map;
import java.util.HashMap;
import java.util.Scanner;

/**
 *
 * @author <a href="mailto:plsm@ua.pt">Pedro Lopes da Silva Mariano</a>
 *
 * @version 1.0 29 de Março de 2010
 */
final public class Sym2x2Description
	extends AbstractDescriptionText<Symmetric2x2Game, Symmetric2x2Strategy>
	implements DescriptionGUI<Symmetric2x2Game, Symmetric2x2Strategy>
{
	final private static String ROOT_NODE = "Symmetric2x2Game";

	/**
	 * Return a map that associates tag names to strategy constructors.
	 */
	static private Map<String, Constructor<? extends Symmetric2x2Strategy>> strategyConstructors ()
	{
		Constructor<Symmetric2x2Strategy> cp;
		Map<String, Constructor<? extends Symmetric2x2Strategy>> result;
		result = new HashMap<String, Constructor<? extends Symmetric2x2Strategy>> ();
		try {
			Class<Symmetric2x2Strategy> c = Symmetric2x2Strategy.class;
			cp = c.getConstructor (Scanner.class);
			result.put (Symmetric2x2Strategy.CONSTRUCTOR_TAG, cp);
		}
		catch (NoSuchMethodException nsme) {
			System.err.println ("Class Symmetric2x2Strategy does not have a constructor with parameter type org.w3c.dom.Element");
			System.exit (1);
			return null;
		}
		return result;
	}

	/**
	 * Return a map that associates tag names to game constructors. The text file should only have a single tag whose name is a key of the returned map.
	 */
	static private Map<String, Constructor<? extends Symmetric2x2Game>> gameConstructors ()
	{
		Constructor<Symmetric2x2Game> cg;
		Map<String, Constructor<? extends Symmetric2x2Game>> result;
		result = new HashMap<String, Constructor<? extends Symmetric2x2Game>> ();
		try {
			Class<Symmetric2x2Game> c = Symmetric2x2Game.class;
			cg = c.getConstructor (Scanner.class);
			result.put (Symmetric2x2Game.CONSTRUCTOR_TAG, cg);
		}
		catch (NoSuchMethodException nsme) {
			System.err.println ("Class Symmetric2x2Game does not have a constructor with parameter type org.w3c.dom.Element");
			System.exit (1);
		}
		return result;
	}

	/**
	 * Creates a new instance of Sym2x2XMLConfigFileParameters
	 */
	public Sym2x2Description ()
	{
		super (gameConstructors (), strategyConstructors (), new intopo.game.impl.sym2x2.FoldSymmetric2x2Strategy ());
	}

	public String getRootNodeName ()
	{
		return ROOT_NODE;
	}
	@Override
	public String getBinDescription (Class<? extends Symmetric2x2Strategy> c, int bin)
	{
		return Symmetric2x2Strategy.getBinDescription (bin);
	}
	/**
	 * Reads the parameters used by all instances of class {@code }
	 * @param scanner
	 * @throws intopo.evogame.partnerselection.config.ParsingException
	 */
	@Override
	public void readGlobalParameters (Scanner scanner)
		throws ParsingException
	{
		Symmetric2x2Strategy.Parameters.read (scanner);
	}
	@Override
	public void writeGlobalParameters (PrintStream ps)
	{
		Symmetric2x2Strategy.Parameters.write (ps);
	}

	@Override
	public AbstractGameEditorComponent<Symmetric2x2Game, Symmetric2x2Strategy> getGameEditorComponent ()
	{
		return new Symmetric2x2GameComponent ();
	}

	@Override
	public AbstractStrategyEditorComponent<Symmetric2x2Strategy> getStrategyEditorComponent ()
	{
		return new Symmetric2x2StrategyComponent ();
	}

	@Override
	public AbstractGlobalParametersComponent getGlobalParametersEditorComponent ()
	{
		return new Symmetric2x2GlobalParametersComponent ();
	}

}
